package com.lky.marshallmall.order.vo;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * Created by
 * autor : Marshall lky
 * datetime: 2021/6/8 19:28
 */
@ToString
public class OrderConfirmVo {
    @Getter @Setter
    private List<MemberAddressVo> memberAddress;
    @Getter @Setter
    private List<OrderItemVo> items;
    //优惠券
    @Getter @Setter
    private Integer integration;

    @Getter @Setter
    private Map<Long, Boolean> stocks;

    //防重令牌
    @Getter @Setter
    private String orderToken;

    public Integer getCount(){
        Integer i = 0;
        if (items!=null){
            for (OrderItemVo itemVo:items){
                i+=itemVo.getCount();
            }
        }
        return i;
    }


    public BigDecimal getTotalPrice() {
        BigDecimal zero = BigDecimal.ZERO;
        if (items!=null){
            for (OrderItemVo itemVo:items){
                BigDecimal multiply = itemVo.getPrice().multiply(new BigDecimal(itemVo.getCount().toString()));
                zero = zero.add(multiply);
            }
        }
        return zero;
    }

    public BigDecimal getPayPrice() {
        BigDecimal zero = BigDecimal.ZERO;
        if (items!=null){
            for (OrderItemVo itemVo:items){
                BigDecimal multiply = itemVo.getPrice().multiply(new BigDecimal(itemVo.getCount().toString()));
                zero = zero.add(multiply);
            }
        }
        return zero;
    }

}
